package com.dofast.bt.adapter;

import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.dofast.bt.R;
import com.dofast.bt.base.BaseApplication;
import com.dofast.bt.bean.GoodsBean;
import com.dofast.bt.bean.ShoppingCartBean;

import org.xutils.ex.DbException;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * username:Created by hsj on 2016/12/8 0008.
 * class：
 * 类描述：确认付款
 */

public class PaymentAdapter extends BaseAdapter {
    private List<ShoppingCartBean> list = new ArrayList<ShoppingCartBean>();


    public PaymentAdapter(List<ShoppingCartBean> list) {
        this.list = list;

    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (null == convertView) {
            convertView = LayoutInflater.from(BaseApplication.getInstance().getApplicationContext()).inflate(R.layout.item_basket, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        //图片
        try {
            Glide.with(BaseApplication.getInstance().getApplicationContext()).load(list.get(position).getGoods().getImg_head()).placeholder(R.mipmap.tea).into(holder.ivPhoto);

        //品牌
        holder.tvBrand.setVisibility(View.GONE);
        //状态
        holder.ivSelcect.setVisibility(View.GONE);
        //茶名
        if (!TextUtils.isEmpty(list.get(position).getGoods().getName())) {
            holder.tvName.setText(list.get(position).getGoods().getName());
        } else {
            holder.tvName.setText("");
        }
        //数量

        holder.tvNum.setText("X  " + list.get(position).getNum());
        //价格

        holder.tvPrice.setText("¥  " + list.get(position).getGoods().getPrice());
        } catch (DbException e) {
            e.printStackTrace();
        }
        return convertView;
    }


    static class ViewHolder {
        @BindView(R.id.tv_brand)
        TextView tvBrand;
        @BindView(R.id.iv_selcect)
        ImageView ivSelcect;
        @BindView(R.id.iv_photo)
        ImageView ivPhoto;
        @BindView(R.id.tv_name)
        TextView tvName;
        @BindView(R.id.tv_price)
        TextView tvPrice;
        @BindView(R.id.tv_num)
        TextView tvNum;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
